Completed
Push — master ( 17f83b...e9467a )
by Taavo-Taur
53s
created

aliases.js ➔ aliasesMixinMaker   B

Complexity

Conditions 2
Paths 3

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 29
rs 8.8571

1 Function

Rating   Name   Duplication   Size   Complexity  
A aliases.js ➔ ... ➔ ??? 0 1 1
1
import {each} from './utils'
2
3
const variables = {
4
	loading: function () {
5
		return this.$loadingSyncers
6
	}
7
}
8
9
const methods = {
10
	refresh: function (...args) {
11
		return this.$refreshSyncers(...args)
12
	},
13
	service: function (...args) {
14
		return this.$feathers.service(...args)
15
	}
16
}
17
18
/**
19
 * Create mixin by passed in options
20
 *
21
 * @param {Boolean|Object} options
22
 */
23
export default function aliasesMixinMaker(options) {
24
	let isEnabled
25
	if (typeof options === 'boolean') {
26
		isEnabled = () => options
27
	} else {
28
		isEnabled = key => {
29
			return key in options && options[key]
30
		}
31
	}
32
33
	const mixin = {
34
		computed: {}, // variables
35
		methods: {}
36
	}
37
38
	each(variables, (getter, key) => {
39
		if (isEnabled(key)) {
1 ignored issue
show
Bug introduced by
The call to isEnabled seems to have too many arguments starting with key.
Loading history...
40
			mixin.computed[`$${key}`] = getter
41
		}
42
	})
43
44
	each(methods, (caller, key) => {
45
		if (isEnabled(key)) {
1 ignored issue
show
Bug introduced by
The call to isEnabled seems to have too many arguments starting with key.
Loading history...
46
			mixin.methods[`$${key}`] = caller
47
		}
48
	})
49
50
	return mixin
51
}
52